﻿
//数组辅助操作
/*

*/

//从数组中删除指定ID的项
Array.prototype.Remove = function (dx) {
    var me = this;
    if (me.splice != undefined) {
        var i = 0;
        var tmp = -1;
        $.each(this, function (i, val) {
            if (this.guid == dx.guid)
                tmp = i;
            ++i;
        });
        if (tmp != -1)
            this.splice(tmp, 1);
    }
}

//数组中是否包含指定ID
Array.prototype.contains = function (dx) {
    var i = 0;
    var tmp = -1;
    var flag = false;
    $.each(this, function (i, val) {
        if (this.ID == dx.ID)
            flag = true;
    });
    return flag;
}

//根据属性名和属性值，查找第一个符合条件的对象
Array.prototype.where = function (dx, propName) {
    var i = 0;
    var tmp = undefined;
    var flag = false;
    if (propName == undefined)
        propName = "guid";
    $.each(this, function (i, val) {
        for (var i in this) {
            if (i == propName && this[i] == dx) {
                tmp = this;
                return false;
            }
        }
    });
    return tmp;
}


//根据属性名和属性值，查找第一个符合条件的对象
Array.prototype.findall = function (dx, propName) {
    var i = 0;
    var result=[]
    if (propName == undefined)
        propName = "guid";
    $.each(this, function (i, val) {
        for (var i in this) {
            if (i == propName && this[i] == dx) {
                result.push( this);
            }
        }
    });
    return result;
}




